﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OOLib
{
   /// <summary>
   /// Provides information regarding the implementation, i.e. which services are implemented and the name of the implementation.
   /// </summary>
   public interface IServiceInfo
   {
      /// <summary>
      /// Gets the implementation name of the service implementation.
      /// </summary>
      string ImplementationName { get; }

      /// <summary>
      /// Tests whether the specified service is supported, i.e. implemented by the implementation.
      /// </summary>
      /// <param name="serviceName">Name of service to be tested </param>
      /// <returns>true, if service is supported, false otherwise</returns>
      bool SupportsService(string serviceName);

      /// <summary>
      /// Provides the supported service names of the implementation, including also indirect service names.
      /// </summary>
      /// <returns>Returns a sequence of service names that are supported.</returns>
      string[] GetSupportedServiceNames();
   }

   /// <summary>
   /// Implementation of the IServiceInfoImpl interface
   /// </summary>
   internal class ServiceInfoImpl : IServiceInfo
   {
      /// <summary>
      /// Constructor
      /// </summary>
      /// <param name="cow">COM object which should support the interface.</param>
      public ServiceInfoImpl(ComObjectWrapper cow)
      {
         Cow = cow;
      }

      /// <summary>
      /// Gets the COM object wrapper which should support the interface.
      /// </summary>
      public ComObjectWrapper Cow { get; private set; }

      /// <summary>
      /// Gets the implementation name of the service implementation.
      /// </summary>
      /// <remarks>!!! Not tested !!!</remarks>
      public string ImplementationName 
      { 
         get
         {
            Cow.CheckDisposed();
            return (string)Cow.InvokeMethod("getImplementationName");
         }
      }

      /// <summary>
      /// Tests whether the specified service is supported, i.e. implemented by the implementation.
      /// </summary>
      /// <param name="serviceName">Name of service to be tested </param>
      /// <returns>true, if service is supported, false otherwise</returns>
      /// <remarks>!!! Not tested !!!</remarks>
      public bool SupportsService(string serviceName)
      {
         Cow.CheckDisposed();
         return (bool)Cow.InvokeMethod("supportsService", serviceName);
      }

      /// <summary>
      /// Provides the supported service names of the implementation, including also indirect service names.
      /// </summary>
      /// <returns>Returns a sequence of service names that are supported.</returns>
      /// <remarks>!!! Not tested !!!</remarks>
      public string[] GetSupportedServiceNames()
      {
         Cow.CheckDisposed();
         return (string[])Cow.InvokeMethod("getSupportedServiceNames");
      }
   }
}
